package com.yjt.gcss.gddw.modules.uiDkxy;

import java.util.Hashtable;

import javax.annotation.Resource;

import org.hibernate.criterion.MatchMode;
import org.hibernate.criterion.Order;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import com.yjt.common.easyui.datagrid.DataGridDTO;
import com.yjt.common.easyui.datagrid.DataGridJsonDTO;
import com.yjt.common.tools.StringUtil;
import com.yjt.common.tools.TimeUtil;
import com.yjt.gcss.gddw.common.bean.domain.InfoSsxy;
import com.yjt.gcss.gddw.common.bean.domain.UiDkxy;
import com.yjt.gcss.gddw.common.dao.InfoSsxyDao;
import com.yjt.gcss.gddw.common.dao.UiDkxyDao;

@Service(UiDkxyService.BEAN_PACKAGE_NAME)
@Transactional(readOnly=true)
public class UiDkxyService {

	public static final String BEAN_PACKAGE_NAME = "com.yjt.gcss.gddw.modules.uiDkxy.UiDkxyService";
	
	@Resource(name = UiDkxyDao.BEAN_PACKAGE_NAME)
	private UiDkxyDao uiDkxyDao;
	
	public DataGridJsonDTO query(DataGridDTO datagrid, UiDkxy queryModel) {
		Hashtable<String, String> paramsTable = new Hashtable<String, String>();
		//交易日期
		if(!StringUtil.isEmpty(queryModel.getQuery_start_date_jyrq())){
			paramsTable.put("query_start_date_jyrq", TimeUtil.changeStrTimeFormat(queryModel.getQuery_start_date_jyrq(), "yyyy-MM-dd", "yyyyMMdd"));
			uiDkxyDao.enableFilter("uiDkxyFilterByJYRQStartDate", paramsTable);
			paramsTable.clear();
		}
		if(!StringUtil.isEmpty(queryModel.getQuery_end_date_jyrq())){
			paramsTable.put("query_end_date_jyrq", TimeUtil.changeStrTimeFormat(queryModel.getQuery_end_date_jyrq(), "yyyy-MM-dd", "yyyyMMdd"));
			uiDkxyDao.enableFilter("uiDkxyFilterByJYRQEndDate", paramsTable);
			paramsTable.clear();
		}
		uiDkxyDao.addOrder(Order.desc("jyrq"));
		uiDkxyDao.addOrder(Order.desc("jysj"));
		DataGridJsonDTO result = uiDkxyDao.getBeansByBeanForPager(queryModel, MatchMode.ANYWHERE, datagrid, true);
		uiDkxyDao.disableFilter("uiDkxyFilterByJYRQStartDate");
		uiDkxyDao.disableFilter("uiDkxyFilterByJYRQEndDate");
		return result;
	}
	
	public UiDkxy view(String jybsh) {
		return (UiDkxy)uiDkxyDao.getBeanById(jybsh);
	}
}
